using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class Script2 : MonoBehaviour
{
	public List<Light> ZLights = new List<Light>();

	public List<Light> YLights = new List<Light>();

	public List<Light> XLights = new List<Light>();

	private List<Light> allLights = new List<Light>();

	private Animation anim;

	public List<AnimationClip> lightbarAnimations = new List<AnimationClip>();

	private bool[] playAnimationShortNormalLong = new bool[3]
	{
		false,
		true,
		false
	};

	private bool RightSideRed = true;

	private bool LeftSideRed;

	private bool lightsFrontON;

	private bool lightsRearON;

	private bool allLightsOffWithoutAnimations;

	private Vector3 frontRot = new Vector3(0f, 90f, 0f);

	private Vector3 rearRot = new Vector3(0f, -90f, 0f);

	private void Start()
	{
		anim = GetComponent<Animation>();
		for (int i = 0; i < ZLights.Count; i++)
		{
			allLights.Add(ZLights[i]);
		}
		for (int j = 0; j < YLights.Count; j++)
		{
			allLights.Add(YLights[j]);
		}
		for (int k = 0; k < XLights.Count; k++)
		{
			allLights.Add(XLights[k]);
		}
		if (RightSideRed)
		{
			foreach (Light allLight in allLights)
			{
				if (HasWord(allLight.gameObject.name, "Red"))
				{
					allLight.color = Color.red;
				}
				else
				{
					allLight.color = Color.blue;
				}
			}
		}
		if (LeftSideRed)
		{
			foreach (Light allLight2 in allLights)
			{
				if (HasWord(allLight2.gameObject.name, "Blue"))
				{
					allLight2.color = Color.red;
				}
				else
				{
					allLight2.color = Color.blue;
				}
			}
		}
	}

	public bool HasNumber(string input)
	{
		return (from x in input
			where char.IsDigit(x)
			select x).Any();
	}

	public bool HasWord(string input, string wordToFind)
	{
		return input.Contains(wordToFind);
	}

	private void Update()
	{
		if (playAnimationShortNormalLong[0])
		{
			anim.clip = lightbarAnimations[0];
		}
		else if (playAnimationShortNormalLong[1])
		{
			anim.clip = lightbarAnimations[1];
		}
		else
		{
			anim.clip = lightbarAnimations[2];
		}
		anim.Play();
		if (allLightsOffWithoutAnimations)
		{
			anim.Stop();
		}
		if (lightsRearON)
		{
			foreach (Light allLight in allLights)
			{
				string name = allLight.gameObject.name;
				if (!HasNumber(name))
				{
					allLight.gameObject.transform.localEulerAngles = rearRot;
				}
			}
		}
		if (lightsFrontON)
		{
			foreach (Light allLight2 in allLights)
			{
				string name2 = allLight2.gameObject.name;
				if (HasNumber(name2))
				{
					allLight2.gameObject.transform.localEulerAngles = frontRot;
				}
			}
		}
		if (allLightsOffWithoutAnimations)
		{
			lightsRearON = false;
			lightsFrontON = false;
			foreach (Light allLight3 in allLights)
			{
				allLight3.enabled = false;
			}
			anim.Stop();
		}
	}
}
